package com.zcx.project.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zcx.project.entity.ZcxDepartment;
import com.zcx.project.mapper.ZcxDepartmentMapper;


@Controller
@RequestMapping("/ZcxDepartment")
public class ZcxDepartmentController {

    @Autowired
    ZcxDepartmentMapper zcxDepartmentMapper;


    @RequestMapping(value = "ZcxDepartmentHtml")
    public ModelAndView getMainPage(HttpSession session, HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("zcxdepartment");
        return mv;
    }

    @ResponseBody
    @RequestMapping(value = "/findList")
    public List findList(ZcxDepartment obj) {
        List list = zcxDepartmentMapper.findList(obj);
        return list;
    }

    @ResponseBody
    @RequestMapping(value = "/query")
    public Map<String, Object> findZcxDepartmentPage(int currentPage, int rows, ZcxDepartment obj) {

        //使用分页插件,核心代码就这一行，页数、每页行数
        PageHelper.startPage(currentPage, rows);
        List<ZcxDepartment> list = zcxDepartmentMapper.findList(obj);
        PageInfo<ZcxDepartment> pageInfo = new PageInfo<ZcxDepartment>(list);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("total", pageInfo.getTotal());
        result.put("rows", pageInfo.getList());
        return result;


    }


    @ResponseBody
    @RequestMapping(value = "/insertZcxDepartment")
    public Map<String, Object> addZcxDepartment(ZcxDepartment obj) {
        int i = zcxDepartmentMapper.insertSelective(obj);
        Map<String, Object> returnMap = new HashMap<String, Object>();
        if (i == 0)
            returnMap.put("showInfo", "添加失败！");
        else
            returnMap.put("showInfo", "添加成功！");
        return returnMap;
    }


    @ResponseBody
    @RequestMapping(value = "/updateZcxDepartment")
    public Map<String, Object> updateZcxDepartment(ZcxDepartment obj) {
        int i = zcxDepartmentMapper.updateByPrimaryKeySelective(obj);
        Map<String, Object> returnMap = new HashMap<String, Object>();
        if (i == 0)
            returnMap.put("showInfo", "修改失败！");
        else
            returnMap.put("showInfo", "修改成功！");
        return returnMap;
    }

    @ResponseBody
    @RequestMapping(value = "/deleteZcxDepartment")
    public Map<String, Object> deleteZcxDepartment(int id) {
        int i = zcxDepartmentMapper.deleteByPrimaryKey(id);
        Map<String, Object> returnMap = new HashMap<String, Object>();
        if (i == 0)
            returnMap.put("showInfo", "删除失败！");
        else
            returnMap.put("showInfo", "删除成功！");
        return returnMap;
    }


}
